import 'dart:io';

import 'package:car/page/down_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../main.dart';
import '../widget/focus_killer.dart';
import 'inventory_page.dart';
import 'move_page.dart';
import 'query_page.dart';
import 'setting_common_page.dart';
import 'up_page.dart';


class Index extends StatefulWidget {
  const Index({Key? key}) : super(key: key);

  @override
  State<Index> createState() => _IndexState();
}

class _IndexState extends State<Index> {

  @override
  initState() {
    super.initState();
    timer.startCountDown();


  }

  @override
  void dispose() {
    // uhfSerialPortHelper.sendData(stop());
    uhfSerialPortHelper.close();
    timer.cancel();
    super.dispose();
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:  Container(
          width: double.infinity,
          height: double.infinity,
          decoration: const BoxDecoration(
            image: DecorationImage(
              fit: BoxFit.fill,
              image: AssetImage(
                "assets/images/bg.png",
              ),
            ),
          ),
          child: Stack(
            alignment: AlignmentDirectional.center,
            children: [
              focusKiller(),
              Positioned(
                top: 40.h,
                child:Image.asset("assets/images/index_title.png",width: 160.w,fit: BoxFit.fitWidth,),
              ),
              Positioned(
                  top: 16.h,
                  right: 10.w,
                  child:InkWell(
                    onTap: (){
                      Get.defaultDialog(
                        title: '退出',
                        titleStyle: TextStyle(
                          color: const Color(0xFF000000),
                          fontSize: 6.sp,
                        ),
                        middleText: '确定退出应用？',
                        middleTextStyle: TextStyle(
                          color: const Color(0xFF000000),
                          fontSize: 4.sp,
                        ),
                        radius: 4.sp,
                        textConfirm: '确定',
                        // textCancel: '取消',
                        confirmTextColor: const Color(0xFF007AFF),
                        backgroundColor: const Color(0xD1F8F8F8),
                        buttonColor: Colors.transparent,
                        onConfirm: () {
                          SystemNavigator.pop();
                          exit(0);
                        },
                      );
                    },
                    child: Image.asset("assets/images/quit.png",width: 35.w,fit: BoxFit.fitWidth,),
                  )
              ),
              Positioned(
                  top: 16.h,
                  right: 55.w,
                  child:InkWell(
                    onTap: (){
                      Get.to(()=>const SettingCommon());
                    },
                    child:Image.asset("assets/images/setting.png",width: 35.w,fit: BoxFit.fitWidth,),
                  )
              ),
              Positioned(
                top: 16.h,
                left: 10.w,
                child:Row(
                  children: [
                    Text(settingEntity.deviceName??'',style: TextStyle(color: Colors.white,fontSize: 9.sp),),
                    Obx(() => Text('  ${timer.time.value}',style: TextStyle(color: Colors.white,fontSize: 9.sp),))
                  ],
                )
              ),
              // Positioned(
              //     top: 16.h,
              //     left: 10.w,
              //     child:Obx(() => Text(timer.time.value,style: TextStyle(color: Colors.white,fontSize: 9.sp),))
              // ),
              Positioned(
                  top: 80.h,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      InkWell(
                        child:  Image.asset("assets/images/inventory.png",height: 250.h,fit: BoxFit.fitHeight,),
                        onTap: (){
                          Get.to(()=> const Inventory());
                        },
                      ),
                      SizedBox(width: 8.h,),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          InkWell(
                            child:  Image.asset("assets/images/up.png",height: 121.h,fit: BoxFit.fitHeight,),
                            onTap: (){
                              Get.to(()=> const Up());
                            },
                          ),
                          SizedBox(height: 8.h,),
                          InkWell(
                            child:  Image.asset("assets/images/query.png",height: 121.h,fit: BoxFit.fitHeight,),
                            onTap: (){
                              Get.to(()=> const Query());
                            },
                          ),
                        ],
                      ),
                      SizedBox(width: 8.h,),
                      Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          InkWell(
                            child:  Image.asset("assets/images/down.png",height: 121.h,fit: BoxFit.fitHeight,),
                            onTap: (){
                              Get.to(()=> const Down());
                            },
                          ),
                          SizedBox(height: 8.h,),
                          InkWell(
                            child:  Image.asset("assets/images/move.png",height: 121.h,fit: BoxFit.fitHeight,),
                            onTap: (){
                              Get.to(()=> const Move());
                            },
                          ),
                        ],
                      ),
                    ],
                  )
              ),
            ],
          )
      )
    );
  }
}